package edu.java.lectures.lec05.polimorphism;

public class TestObjectInitializtion {

    public static void main(String[] args) {
	// Object initialization sequence:
	// 1) static blocks execution (executed ONLY ONCE)
	// 2) "dynamic" block execution (top -> down)
	// 3) super constructors from the inheritance tree (top -> down)
	// 4) this constructors (if they are invoked)
	// 5) current constructor

	// ScaleneTriangle raznostranenTr1 = new ScaleneTriangle(1, 2, 3);
	//	
	// ScaleneTriangle raznostranenTr2 = new ScaleneTriangle(1, 2, 3);
	// ScaleneTriangle raznostranenTr3 = raznostranenTr1;

	// TEST 1
	// test static and dynamic block of codes
	// here "ScaleneTriangle" must be the first invoking of the class in the
	// main method. You'll see that in this case the dynamic block of codes
	// won't execute. Only static blocks will do it.
	// System.out.println(ScaleneTriangle.test);
	// ScaleneTriangle.test();

	// TEST 2
	// look the sequence of execution of static/dymanic blocks, super() and
	// this().
	// IsoscelesTriangle iso= new IsoscelesTriangle(1,2);

	// TEST 3
	// catching a base class's field which have the same name with a child
	// class's field
//	IsoscelesTriangle object = new IsoscelesTriangle(1, 2);
//	System.out.println(" \nCathcing fileds:");
//	System.out.println("object.a: " + object.a);
//	System.out.println("object.super.a: "
//		+ ((EquilateralTriangle) object).a);
//
//	System.out.println(" \nCathcing getters:");
//	System.out.println("object.getA(): " + object.getA());
//	System.out.println("??? object.super.getA(): "
//		+ ((EquilateralTriangle) object).getA());
//
//	System.out.println(" \nCathcing static fileds:");
//	System.out.println(IsoscelesTriangle.statA);
//	System.out.println(((EquilateralTriangle) object).statA);

	// variable -> object
	// instance variables -> object instanceof ObjectType
	// class variables -> variable instsanceof VariableType
	// ASF= A Static Field ; CDF= C Dynamic Field
	// A.ASF <- B <- C.CDF
	// A a = new C();
	// ((C)a).CDF;
	// a.ASF
	// a.CDF
	
	EquilateralTriangle reference = new IsoscelesTriangle(1, 5);
	System.out.println(((IsoscelesTriangle)reference).b);
	System.out.println(reference.statA);
	System.out.println(((IsoscelesTriangle)reference).statA);
	// System.out.println(reference.statB);  // without explicit casting,
	//the "reference" can't see the static field "statB" of class IsoscelesTriangle
	
	System.out.println(((IsoscelesTriangle)reference).statB);
    }
}
